<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Banner;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BannerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Banner(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type','类型')->using(['首页顶部轮播','首页中部轮播','商城页轮播'])->label(['info','primary','warning']);
            $grid->column('image')->image(null,50,50);
            $grid->column('jump','跳转设置')->using(\App\Models\Banner::$jumpList)->label('primary');
            $grid->column('sort')->sortable();
            $grid->column('status')->radio(['正常','隐藏'],true)->label(['info','default']);
            $grid->column('created_at');
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Banner(), function (Show $show) {
            $show->field('id');
            $show->field('image');
            $show->field('sort');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Banner(), function (Form $form) {
            $form->select('type')->options(['首页顶部轮播【尺寸：375*258】','首页中部轮播【尺寸：346*138】','商城页轮播【尺寸：347*140】'])->default(0);
            $form->image('image')->uniqueName()->autoUpload()->required();
            $form->select("jump","跳转设置")->options(\App\Models\Banner::$jumpList)->default("not")->required();
            $form->number('sort')->default(0);
            $form->radio('status')->options(['正常','隐藏'])->default(0);
        });
    }
}
